<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use DB;
use Illuminate\Http\Request;


class OperationLog extends Authenticatable
{
    use Notifiable;
	protected $table = 'admin_operation_log';


    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'remember_token',
    ];

    public  static  function getOperationLogList(){
	    $users = DB::table('admin_operation_log')
		    ->join('users', 'admin_operation_log.user_id', '=', 'users.id')
		    ->where('is_del',1)
		    ->select('admin_operation_log.*', 'users.name as user_name')
		    ->get()
		    ->toArray();
	    if(!$users){
		    return array();
	    }
	    return $users;
    }

    public static function saveOperationLog(Request $request,$userID,$logs){
	    $operationLg = new OperationLog();
	    $operationLg->user_id =$userID;
	    $operationLg->path =$request->path();
	    $operationLg->method =$request->method();
	    $operationLg->ip =$request->getClientIp();
	    $operationLg->logs =$logs;
	    $operationLg->input =json_encode($request->input());
	    if(!$operationLg->save()) return -1;
	    return  1;

    }



}
